package com.changgou.utils;


import com.changgou.pojo.SkuInfo;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

public class SortedUtils {

    // 排序 升序
    public static List<SkuInfo> sortedByAsc(List<SkuInfo> list){
        return list.stream().sorted(Comparator.comparing(SkuInfo::getPrice)).collect(Collectors.toList());
    }

    // 降序
    public static List<SkuInfo> sortedByDesc(List<SkuInfo> list){
        return list.stream().sorted(Comparator.comparing(SkuInfo::getPrice).reversed()).collect(Collectors.toList());
    }

    // 分页
    public static List<SkuInfo> sortedByPage(List<SkuInfo> list,int pageNum, int pageSize){
        List<SkuInfo> skip = list.stream().skip((pageNum - 1) * pageSize).collect(Collectors.toList());
       return skip.stream().limit(pageNum * pageSize).collect(Collectors.toList());
    }

}
